package zyn_hy_login;

public class zyn2
{
	private String[] ActionSafe;
	private String[] AttributeSafe;
	private boolean result;
	protected String strConn;
	protected static String strSQL;

	public zyn2()
	{
		this.strConn = ConfigurationSettings.AppSettings["connectString"];
	}

	public zyn2(String[] safe_action)
	{
		this.strConn = ConfigurationSettings.AppSettings["connectString"];
		this.ActionSafe = safe_action;
		this.zyn2SeparateSafe();
	}

	private boolean Check_FolderSafe(String[] FolderSafe)
	{
		FolderSafe[0] = (new SecurityZ8()).Decrypt(FolderSafe[0]);
		switch (FolderSafe[1])
		{
			case "R":
				if (FolderSafe[0].substring(0, 1).equals("1"))
				{
					this.result = false;
				}
				else
				{
					this.result = true;
				}
				break;

			case "D":
				if (FolderSafe[0].substring(1, 2).equals("1"))
				{
					this.result = false;
				}
				else
				{
					this.result = true;
				}
				break;

			case "W":
				if (FolderSafe[0].substring(2, 3).equals("1"))
				{
					this.result = false;
				}
				else
				{
					this.result = true;
				}
				break;

			case "C":
				if (FolderSafe[0].substring(3, 4).equals("1"))
				{
					this.result = false;
				}
				else
				{
					this.result = true;
				}
				break;
		}
		return this.getResult();
	}

	public final boolean CheckFolderSafe(String[] CheckString)
	{
		switch (CheckString[2])
		{
			case "file":
				if ((!CheckString[0].equals("")) && (CheckString[0].length() >= 8))
				{
					String[] stra = new String[2];
					stra[1] = CheckString[3];
					stra[0] = CheckString[0];
					this.CheckSafe(stra);
//C# TO JAVA CONVERTER TODO TASK: There is no 'goto' in Java:
					goto Label_00B2;
				}
				this.result = false;
				break;

			case "folder":
				if ((CheckString[1].equals("")) || (CheckString[1].length() < 8))
				{
					this.result = false;
				}
				else
				{
					String[] folderSafe = new String[2];
					folderSafe[1] = CheckString[3];
					folderSafe[0] = CheckString[1];
					this.Check_FolderSafe(folderSafe);
				}
//C# TO JAVA CONVERTER TODO TASK: There is no 'goto' in Java:
				goto Label_00B2;
		}
	Label_00B2:
		return this.getResult();
	}

	public final boolean CheckSafe(String[] stra)
	{
		this.ActionSafe = stra;
		this.zyn2SeparateSafe();
		return this.getResult();
	}

	public final String GetCommonZYN(String strId, String strId2, String strId3)
	{
		SqlConnection connection = new SqlConnection(this.strConn);
		strSQL = "select x50 from z8 where id=" + strId + " and id2=" + strId2 + " and id3=" + strId3 + "";
		SqlCommand command = new SqlCommand(strSQL, connection);
		connection.Open();
		SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
		if (reader.Read())
		{
			reader.Close();
			return reader.GetString(0);
		}
		reader.Close();
		return "";
	}

	private void zyn2SeparateSafe()
	{
		SecurityZ8 yz = new SecurityZ8();
		String text = yz.Decrypt(this.ActionSafe[0]);
		if (text.equals(""))
		{
			this.result = false;
		}
		else
		{
			text = text.replace("0", "false").replace("*", "true");
			char[] separator = new char[] {'/'};
			this.AttributeSafe = new String[yz.Decrypt(this.ActionSafe[0]).split(java.util.regex.Pattern.quote(separator.toString()), -1).getLength()];
			this.AttributeSafe = text.split(java.util.regex.Pattern.quote(separator.toString()), -1);
			switch (this.ActionSafe[1])
			{
				case "R":
					if (this.AttributeSafe[0].equals("true"))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;

				case "W":
					if (this.AttributeSafe[2].equals("true"))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;

				case "A":
					if (this.AttributeSafe[4].equals("true"))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;

				case "D":
					if (this.AttributeSafe[6].equals("true"))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;

				case "E":
					if (this.AttributeSafe[8].equals("true"))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;

				case "RWADE":
					if ((((this.AttributeSafe[0].equals("true")) && (this.AttributeSafe[2].equals("true"))) && ((this.AttributeSafe[4].equals("true")) && (this.AttributeSafe[6].equals("true")))) && (this.AttributeSafe[8].equals("true")))
					{
						this.result = true;
					}
					else
					{
						this.result = false;
					}
					break;
			}
		}
	}

	public final boolean getResult()
	{
		return this.result;
	}
}